import { FinalTree } from "./FinalTree";
import { SArenaCrossFinalBattles } from "../../../../../../Message/Public/SArenaCrossFinalBattles";
import { SArenaCrossFinalBattle } from "../../../../../../Message/Public/SArenaCrossFinalBattle";
import { ENodeData } from "../data/ENodeData";
import { Cache } from "../../../../cache/Cache";
import { EArenaProcess } from "../../../../../../Message/Public/EArenaProcess";
import { LevelLimitDefin } from "../../../../../common/defin/LevelLimitDefin";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { FinalNode } from "../data/FinalNode";
import { ObjCreate } from "../../../common/ObjCreate";
import { Language } from "../../../../../../extend/language/Language";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { ArenaCrossBetWindow } from "../ArenaCrossBetWindow";
import { GetVideoData } from "../data/GetVideoData";
import { SArenaCrossGroupBattleEnd } from "../../../../../../Message/Public/SArenaCrossGroupBattleEnd";
//class FinalMatchTree
    
    export  class FinalMatchTree extends FinalTree
    {
        constructor()
        {
            super();
            this._btnArray = [];
            return;
        }

        public updateFinalBattles(arg1: SArenaCrossFinalBattles): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            this._finalBattles = arg1;
            drawLines();
            resetNodes();
            var loc1=0;
            while (loc1 < arg1.finalBattles.length) 
            {
                loc2 = arg1.finalBattles[loc1] as SArenaCrossFinalBattle;
                loc3 = 0;
                while (loc3 < loc2.positions.length) 
                {
                    if ((loc4 = getNoteAtNum(loc2.positions[loc3])).leftChild) 
                    {
                        loc4.data = ENodeData.DATAVIDEO;
                    }
                    else 
                    {
                        loc4.data = ENodeData.DATANULL;
                    }
                    if (loc3 != (loc2.positions.length - 1)) 
                    {
                        drawLine(loc4, 4278255360, 2);
                    }
                    else if (loc5 = loc4.parent) 
                    {
                        if (arg1.battleNumInRing == 0 && arg1.ring + loc5.depth == 4 && !(Cache.instance.arenaCross.arenaCrossInfo && Cache.instance.arenaCross.arenaCrossInfo.process == EArenaProcess._EArenaFinalMatch2 && !Cache.instance.arenaCross.arenaCrossInfo.isOpen && !Cache.instance.arenaCross.isWillOpen)) 
                        {
                            if (Cache.instance.role.entityInfo.level >= LevelLimitDefin.ArenaCrossMinEnterLevel) 
                            {
                                loc5.data = ENodeData.DATABET;
                            }
                            else 
                            {
                                loc5.data = ENodeData.DATANULL;
                            }
                        }
                        else if (loc2.arenaId != 0) 
                        {
                            loc5.data = ENodeData.DATALOOK;
                            loc5.arenaId = loc2.arenaId;
                        }
                        else 
                        {
                            loc5.data = ENodeData.DATAVIDEO;
                        }
                    }
                    ++loc3;
                }
                ++loc1;
            }
            if (this._isShowBtns) 
            {
                this.drawBtns();
            }
            return;
        }

        protected drawBtns(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc1=0;
            loc1 = 0;
            while (loc1 < this._btnArray.length) 
            {
                loc2 = this._btnArray[loc1] as GButton;
                if (loc2.parent) 
                {
                    loc2.parent.removeChild(loc2);
                }
                ++loc1;
            }
            this._btnArray = [];
            loc1 = 0;
            while (loc1 < _noteArray.length) 
            {
                loc3 = _noteArray[loc1] as FinalNode;
                (loc4 = new Object /* flash.accessibility.AccessibilityProperties */()).description = loc3.num + "," + loc3.arenaId;
                loc5 = -20 + loc3.x;
                loc6 = -10 + loc3.y;
                if (!loc3.parent) 
                {
                    loc6 = loc6 + 80;
                }
                if (loc3.data == ENodeData.DATAVIDEO) 
                {
                    loc7 = ObjCreate.createGButton(Language.getString(44338), loc5, loc6, 40, 21, this, "ArenaRedBtn");
                    loc4.description = loc4.description + ("," + ENodeData.DATAVIDEO);
                    loc7.accessibilityProperties = loc4;
                    loc7.addEventListener(flash.events.MouseEvent.CLICK, this.onClickVideo);
                    this._btnArray.push(loc7);
                }
                if (loc3.data != ENodeData.DATALOOK) 
                {
                    if (loc3.data == ENodeData.DATABET) 
                    {
                        loc9 = ObjCreate.createGButton(Language.getString(44340), loc5, loc6, 40, 21, this, "ArenaRedBtn");
                        loc4.description = loc4.description + ("," + ENodeData.DATABET);
                        loc9.accessibilityProperties = loc4;
                        loc9.addEventListener(flash.events.MouseEvent.CLICK, this.onClickPet);
                        this._btnArray.push(loc9);
                    }
                }
                else 
                {
                    loc8 = ObjCreate.createGButton(Language.getString(44339), loc5, loc6, 40, 21, this, "ArenaRedBtn");
                    loc4.description = loc4.description + ("," + ENodeData.DATALOOK);
                    loc8.accessibilityProperties = loc4;
                    loc8.addEventListener(flash.events.MouseEvent.CLICK, this.onClickLook);
                    this._btnArray.push(loc8);
                }
                ++loc1;
            }
            return;
        }

        /* internal  */onClickLook(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as GButton;
            var loc2=int(loc1.accessibilityProperties.description.split(",")[1]);
            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossLookBattle, loc2));
            return;
        }

        /* internal  */onClickPet(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as GButton;
            var loc2=int(loc1.accessibilityProperties.description.split(",")[0]);
            var loc3;
            var loc4=(loc3 = getNoteAtNum(loc2)).leftChild;
            if (this._finalBattles && loc4) 
            {
                ArenaCrossBetWindow.instance.show();
                ArenaCrossBetWindow.instance.setPlayerData(this._finalBattles.finalPosType, loc4.num);
            }
            return;
        }

        /* internal  */onClickVideo(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as GButton;
            var loc2=int(loc1.accessibilityProperties.description.split(",")[0]);
            var loc3;
            var loc4=(loc3 = getNoteAtNum(loc2)).leftChild;
            if (this._finalBattles && loc4) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGetVideo, new GetVideoData(this._finalBattles.finalPosType, loc4.num)));
            }
            return;
        }

        public updateBattleEnd(arg1: SArenaCrossGroupBattleEnd): void
        {
            var loc1=0;
            var loc2=null;
            if (this._finalBattles) 
            {
                loc1 = 0;
                while (loc1 < this._finalBattles.finalBattles.length) 
                {
                    loc2 = this._finalBattles.finalBattles[loc1] as SArenaCrossFinalBattle;
                    if (loc2.arenaId == arg1.arenaId) 
                    {
                        loc2.arenaId = 0;
                        this.updateFinalBattles(this._finalBattles);
                    }
                    ++loc1;
                }
            }
            return;
        }

        public get isShowBtns(): Boolean
        {
            return this._isShowBtns;
        }

        public set isShowBtns(arg1: Boolean)
        {
            this._isShowBtns = arg1;
            return;
        }

        protected /* var */_btnArray: Array<any>;

        protected /* var */_finalBattles: SArenaCrossFinalBattles;

        /* internal */ /* var */_isShowBtns: Boolean=true;
    }
